<template>
	<view class="container">
		<u-navbar title='开处方' :title-bold='true' :border-bottom='false' :is-fixed='true'></u-navbar>
		<!--  -->
		<view class="main">
			<view class="card">
				<view class="pading title">患者信息</view>
				<u-line />
				<view class="content pading">
					<span>姓名：{{info.member_info.username||''}}</span>
					<span>性别：{{info.member_info.gender_text||''}}</span>
					<span>年龄：{{info.member_info.age||''}}</span>
					<span>日期：{{info.createday||''}}</span>
				</view>
			</view>

			<u-form>
				<view class="card">
					<view class="pading title">诊断结果</view>
					<view class="content ">
						<u-form-item :border-bottom='false'>
							<u-input :maxlength='200' type="textarea" placeholder="请填写诊断结果" v-model="form.result" />
						</u-form-item>
						<p style="text-align: end;">{{form.result.length||0}}/200</p>
					</view>
				</view>
				<view class="card">
					<view class="pading title">处方信息</view>
					<u-line />
					<view class="content " v-for="(itm,index) in form.drug" :key="index">
						<view class="lable">
							<span>{{itm.title}}</span>
							<image @click="del(index)" src="../../static/icon/del2.png" mode=""></image>
						</view>
						<u-form-item>
							<u-input :custom-style="{color:'#6EC9E1','font-size':'14px'}" :border-bottom='true'
								:maxlength='200' placeholder="请填写用法说明" v-model="itm.remark" />
						</u-form-item>
					</view>

					<view class="add pading" @click="goTo('/sub/prescription/medication')">+ 添加</view>
				</view>
				<view class="card">
					<view class="pading title">护航员嘱咐</view>
					<view class="content">
						<u-form-item :border-bottom='false'>
							<u-input :maxlength='200' type="textarea" placeholder="请填写护航员嘱咐" v-model="form.tell" />
						</u-form-item>
						<p style="text-align: end;">{{form.tell.length||0}}/200</p>
					</view>
				</view>

			</u-form>
			<view class="btn" @click="show=true">确定</view>
		</view>

		<!-- 提示 -->
		<u-modal v-model="show" :content="content" @confirm="submit" :show-cancel-button="true"></u-modal>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		zixunDetail,
		prescription
	} from '@/api/index.js'
	export default {
		data() {
			return {
				info: '',
				show: false,
				content: '是否确认无误?',
				user: {},
				prescription: '',
				form: {
					result: '',
					tell: '',
					drug: []
				},
			}
		},
		onLoad(e) {
			console.log('-------------------------');
			this.form.advice_id = e.id;
			console.log('that.form.advice_id', this.form.advice_id);
			console.log('-------------------------');
			this.init(e.id)
		},

		methods: {
			del(index) {
				this.form.list.splice(index, 1)
			},
			goTo(url) {
				uni.navigateTo({
					url: url
				})
			},
			submit() {
				let that = this
				prescription(that.form).then(res => {
					that.$refs.uToast.show({
						title: res.msg
					})
					if (res.code == 1) {
						uni.redirectTo({
							url: '/sub/prescription/index?id=' + res.data.id
						})
					}
				})
			},
			medication(e) {
				let obj = {
					"drug_id": e.id,
					"title": e.title
				}
				this.form.drug.push(obj)
				this.$forceUpdate()
			},
			init(id) {
				let that = this
				that.user = that.ws.getUserInfo()
				zixunDetail({
					'id': id
				}).then(res => {
					if (res.code == 1) {
						that.info = res.data.detail

					} else {
						that.$refs.uToast.show({
							title: res.msg
						})
					}
				})

			},


		}
	}
</script>

<style lang="less" scoped>
	.pading {
		padding: 20rpx !important;
	}

	.title {
		font-weight: bold;
		font-size: 18px;
	}

	.container {
		height: 100vh;
		background-color: #EEE;

		.main {
			padding: 10rpx 30rpx;
			padding-bottom: 80rpx;

			.card {
				background-color: #FFF;
				border-radius: 20rpx;
				padding: 20rpx 0;
				margin-top: 30rpx;
			}

			.lable {
				display: flex;
				justify-content: space-between;
				align-items: center;

				span {
					margin-top: unset;
				}
			}

			.add {
				color: #6EC9E1;
				max-width: 50vw;
				text-align: center;
				margin: 0 auto;
			}

			.content {
				width: 100%;
				padding: 0 20rpx;

				span {
					display: inline-block;
					min-width: 50%;
					margin-top: 20rpx;
				}

				p {
					font-size: 14px;
					margin: 20rpx 0;
					color: #B2B2B2;
				}

				text {
					color: #666666;
				}

				image {
					height: 16px;
					width: 16px;
					padding: 30rpx 30rpx 30rpx 80rpx;
				}

			}
		}


	}
</style>